package com.spic.business.manual.controller;

import com.spic.business.ioc.domain.ForecastPreModel;
import com.spic.business.ioc.domain.ForecastWindModel;
import com.spic.business.manual.domain.SecurityCheckManual;
import com.spic.business.manual.domain.WeatherReport;
import com.spic.business.manual.service.ISecurityCheckManualService;
import com.spic.common.core.utils.poi.ExcelUtil;
import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.web.page.TableDataInfo;
import com.spic.common.log.annotation.Log;
import com.spic.common.log.enums.BusinessType;
import com.spic.common.security.annotation.PreAuthorize;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.TextStyle;
import java.time.temporal.TemporalAccessor;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 迎检报告信息主Controller
 *
 * @author spic
 * @date 2022-06-13
 */
@RestController
@RequestMapping("/manual")
public class SecurityCheckManualController extends BaseController
{
    @Autowired
    private ISecurityCheckManualService securityCheckManualService;

    /**
     * 查询迎检报告信息主列表
     */
    @PreAuthorize(hasPermi = "business:manual:list")
    @GetMapping("/list")
    public TableDataInfo list(SecurityCheckManual securityCheckManual)
    {
        startPage();
        List<SecurityCheckManual> list = securityCheckManualService.selectSecurityCheckManualList(securityCheckManual);
        return getDataTable(list);
    }

    /**
     * 导出迎检报告信息主列表
     */
    @PreAuthorize(hasPermi = "business:manual:export")
    @Log(title = "迎检报告信息主", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SecurityCheckManual securityCheckManual) throws IOException
    {
        List<SecurityCheckManual> list = securityCheckManualService.selectSecurityCheckManualList(securityCheckManual);
        ExcelUtil<SecurityCheckManual> util = new ExcelUtil<SecurityCheckManual>(SecurityCheckManual.class);
        util.exportExcel(response, list, "迎检报告信息主数据");
    }

    /**
     * 获取迎检报告信息主详细信息
     */
    @PreAuthorize(hasPermi = "business:manual:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(securityCheckManualService.selectSecurityCheckManualById(id));
    }

    /**
     * 新增迎检报告信息主
     */
    @PreAuthorize(hasPermi = "business:manual:add")
    @Log(title = "迎检报告信息主", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SecurityCheckManual securityCheckManual)
    {
        return toAjax(securityCheckManualService.insertSecurityCheckManual(securityCheckManual));
    }

    /**
     * 修改迎检报告信息主
     */
    @PreAuthorize(hasPermi = "business:manual:edit")
    @Log(title = "迎检报告信息主", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SecurityCheckManual securityCheckManual)
    {
        return toAjax(securityCheckManualService.updateSecurityCheckManual(securityCheckManual));
    }

    /**
     * 删除迎检报告信息主
     */
    @PreAuthorize(hasPermi = "business:manual:remove")
    @Log(title = "迎检报告信息主", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(securityCheckManualService.deleteSecurityCheckManualByIds(ids));
    }

    @GetMapping("sevenDayWeather")
    public AjaxResult get7DayWeather()
    {
        return AjaxResult.success(securityCheckManualService.get7DayWeatherReport());
    }

    @GetMapping("downloadReport/{id}")
    public void  downloadReport(@PathVariable("id") Long id, HttpServletResponse response)
    {
        securityCheckManualService.downloadReport(id, response);
    }


}
